Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPLUGIN-495] WARNINGs based on usage of @Component for MavenSession/MavenProject instead of @Parameter #253

Closed
wants to merge 1 commit into from

Conversation

michael-o
Copy link
Member

This closes #253

@slawekjaranowski
Copy link
Member

We also have the same in JavaJavadocMojoDescriptorExtractor should be removed too.

@michael-o
Copy link
Member Author

We also have the same in JavaJavadocMojoDescriptorExtractor should be removed too.

Working on it. At some point (4.0.0) we should consider dropping support for Javadoc style, only annotation style should remain.

@michael-o
Copy link
Member Author

I jave just tried a snapshot against Maven Dependency Plugin as @khmarbaise has reported. I get:

[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR]   TestCollectMojo.testCollectTestEnvironment:44->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.project.MavenProject, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.execution.scope.internal.MojoExecutionScopeCoreModule)
  while locating org.apache.maven.project.MavenProject
  while locating org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:collect)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:collect
[ERROR]   TestCollectMojo.testCollectTestEnvironment_excludeTransitive:71->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.project.MavenProject, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.execution.scope.internal.MojoExecutionScopeCoreModule)
  while locating org.apache.maven.project.MavenProject
  while locating org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:collect)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:collect
[ERROR]   TestCollectMojo.testSilent:95->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.project.MavenProject, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.execution.scope.internal.MojoExecutionScopeCoreModule)
  while locating org.apache.maven.project.MavenProject
  while locating org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:collect)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:collect
[ERROR]   TestGetMojo.setUp:54->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.execution.MavenSession, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.session.scope.internal.SessionScopeModule)
  while locating org.apache.maven.execution.MavenSession
  while locating org.apache.maven.plugins.dependency.GetMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get
[ERROR]   TestGetMojo.setUp:54->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.execution.MavenSession, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.session.scope.internal.SessionScopeModule)
  while locating org.apache.maven.execution.MavenSession
  while locating org.apache.maven.plugins.dependency.GetMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get
[ERROR]   TestGetMojo.setUp:54->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.execution.MavenSession, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.session.scope.internal.SessionScopeModule)
  while locating org.apache.maven.execution.MavenSession
  while locating org.apache.maven.plugins.dependency.GetMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get
[ERROR]   TestGetMojo.setUp:54->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.execution.MavenSession, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.session.scope.internal.SessionScopeModule)
  while locating org.apache.maven.execution.MavenSession
  while locating org.apache.maven.plugins.dependency.GetMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:get
[ERROR]   TestListClassesMojo.setUp:45->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.execution.MavenSession, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.session.scope.internal.SessionScopeModule)
  while locating org.apache.maven.execution.MavenSession
  while locating org.apache.maven.plugins.dependency.ListClassesMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:list-classes)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:list-classes
[ERROR]   TestListClassesMojo.setUp:45->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.execution.MavenSession, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.session.scope.internal.SessionScopeModule)
  while locating org.apache.maven.execution.MavenSession
  while locating org.apache.maven.plugins.dependency.ListClassesMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:list-classes)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:list-classes
[ERROR]   TestListClassesMojo.setUp:45->AbstractMojoTestCase.lookupMojo:355->AbstractMojoTestCase.lookupMojo:410->PlexusTestCase.lookup:205 � ComponentLookup com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.execution.MavenSession, annotation=[none]] outside of a scoping block
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule -> org.apache.maven.session.scope.internal.SessionScopeModule)
  while locating org.apache.maven.execution.MavenSession
  while locating org.apache.maven.plugins.dependency.ListClassesMojo
  at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:list-classes)

1 error
      role: org.apache.maven.plugin.Mojo
  roleHint: org.apache.maven.plugins:maven-dependency-plugin:3.6.2-SNAPSHOT:list-classes

I guess something is missing on the test classpath, but I have no idea what...

asfgit pushed a commit that referenced this pull request Dec 28, 2023
@michael-o
Copy link
Member Author

@cstamas Any ideas?

@cstamas
Copy link
Member

cstamas commented Dec 28, 2023

OutOfScopeException of MavenSession. You used Maven 4.0.0-alpha-10?

@michael-o
Copy link
Member Author

michael-o commented Dec 28, 2023

OutOfScopeException of MavenSession. You used Maven 4.0.0-alpha-10?

No, 3.8.8.

@cstamas
Copy link
Member

cstamas commented Dec 28, 2023

Hm, with 3.9.6 it "works for me"

@michael-o
Copy link
Member Author

Hm, with 3.9.6 it "works for me"

Did you build a snapshot of this and apply it to Maven Dependency Plugin?

D:\Entwicklung\Projekte\maven-dependency-plugin [master ≡ +0 ~1 -0 !]> git diff
diff --git a/pom.xml b/pom.xml
index c73b619d..3509d46c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -95,22 +95,11 @@ under the License.
     <project.build.outputTimestamp>2023-10-20T21:21:50Z</project.build.outputTimestamp>
     <slf4j.version>1.7.36</slf4j.version>
     <plexus-archiver.version>4.9.0</plexus-archiver.version>
+    <maven.plugin.tools.version>3.10.3-SNAPSHOT</maven.plugin.tools.version>
   </properties>

   <dependencyManagement>
     <dependencies>
-      <!-- TODO check with Maven Api upgrade -->
-      <!-- the same version as in Maven 3.1.1 -->
-      <dependency>
-        <groupId>org.eclipse.sisu</groupId>
-        <artifactId>org.eclipse.sisu.inject</artifactId>
-        <version>0.3.0.M1</version>
-      </dependency>
-      <dependency>
-        <groupId>org.eclipse.sisu</groupId>
-        <artifactId>org.eclipse.sisu.plexus</artifactId>
-        <version>0.3.0.M1</version>
-      </dependency>
       <!-- override the version from maven-reporting-impl -->
       <dependency>
         <groupId>org.apache.commons</groupId>
@@ -318,6 +307,12 @@ under the License.
       <artifactId>maven-plugin-testing-harness</artifactId>
       <version>${pluginTestingVersion}</version>
       <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-container-default</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>

@cstamas
Copy link
Member

cstamas commented Dec 28, 2023

hm, nope, i assumed this PR fails to build....

@michael-o
Copy link
Member Author

hm, nope, i assumed this PR fails to build....

It works, but not the subsequent use in tests. ITs do work, actually. So I guessed that some dep is missing during tests.

@slawekjaranowski
Copy link
Member

hm, nope, i assumed this PR fails to build....

It works, but not the subsequent use in tests. ITs do work, actually. So I guessed that some dep is missing during tests.

Or unit test simply try to lookup Mojo without calling org.apache.maven.execution.scope.internal.MojoExecutionScope#enter

@slawekjaranowski
Copy link
Member

@slawekjaranowski
Copy link
Member

We can remove org.apache.maven.tools.plugin.util.PluginUtils#MAVEN_COMPONENTS

@slawekjaranowski
Copy link
Member

Parameter list can be null ... we also need a fix like:

--- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java
+++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java
@@ -21,9 +21,11 @@ package org.apache.maven.plugins.plugin.descriptor;
 import java.io.Reader;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.Parameter;
@@ -87,7 +89,8 @@ public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder {
 
         PlexusConfiguration[] parameterConfigurations = c.getChild("parameters").getChildren("parameter");
 
-        List<Parameter> parameters = new ArrayList<>(mojoDescriptor.getParameters());
+        List<Parameter> parameters = new ArrayList<>(
+                Optional.ofNullable(mojoDescriptor.getParameters()).orElseGet(Collections::emptyList));
         Map<String, Parameter> parameterMap = new LinkedHashMap<>(mojoDescriptor.getParameterMap());
 
         for (PlexusConfiguration d : parameterConfigurations) {
@@ -108,7 +111,9 @@ public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder {
         }
 
         // clear() is required for maven < 3.6.2
-        mojoDescriptor.getParameters().clear();
+        if (mojoDescriptor.getParameters() != null) {
+            mojoDescriptor.getParameters().clear();
+        }

@michael-o
Copy link
Member Author

Parameter list can be null ... we also need a fix like:

--- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java
+++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java
@@ -21,9 +21,11 @@ package org.apache.maven.plugins.plugin.descriptor;
 import java.io.Reader;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.Parameter;
@@ -87,7 +89,8 @@ public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder {
 
         PlexusConfiguration[] parameterConfigurations = c.getChild("parameters").getChildren("parameter");
 
-        List<Parameter> parameters = new ArrayList<>(mojoDescriptor.getParameters());
+        List<Parameter> parameters = new ArrayList<>(
+                Optional.ofNullable(mojoDescriptor.getParameters()).orElseGet(Collections::emptyList));
         Map<String, Parameter> parameterMap = new LinkedHashMap<>(mojoDescriptor.getParameterMap());
 
         for (PlexusConfiguration d : parameterConfigurations) {
@@ -108,7 +111,9 @@ public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder {
         }
 
         // clear() is required for maven < 3.6.2
-        mojoDescriptor.getParameters().clear();
+        if (mojoDescriptor.getParameters() != null) {
+            mojoDescriptor.getParameters().clear();
+        }

Thanks, working on this.

I consider org.apache.maven.plugin.descriptor.MojoDescriptor.setParameters(List<Parameter>) to be misdesigned. This method uses #addParameter() instead of replacing the entire list. Or the method should be org.apache.maven.plugin.descriptor.MojoDescriptor.addParameters(List<Parameter>).

asfgit pushed a commit that referenced this pull request Dec 29, 2023
asfgit pushed a commit that referenced this pull request Dec 30, 2023
asfgit pushed a commit that referenced this pull request Dec 30, 2023
@michael-o
Copy link
Member Author

I have changed the comment regarding 3.6.2 because that statement is wrong.

@michael-o
Copy link
Member Author

If I don't hear any objections the next couple of days I will merge this PR and the one with the docs update. @slawekjaranowski's fix on MDEP can be applied to all affected plugins moving to MPLUGIN 3.11.0.

@gnodet
Copy link
Contributor

gnodet commented Jan 7, 2024

Sorry for the late intervention. I'm not completely sure about discouraging the use of ${project.xxx} expressions.
The reason is that they may be needed to understand what the exact input is for a given plugin and to find if the input has changed. This may be used by maven build cache extension, and this may be also used in the future if we can actually come up with an incremental build context api. If plugins are only injected with the project, any change to it may cause a rebuild or cache miss.

@michael-o
Copy link
Member Author

Sorry for the late intervention. I'm not completely sure about discouraging the use of ${project.xxx} expressions. The reason is that they may be needed to understand what the exact input is for a given plugin and to find if the input has changed. This may be used by maven build cache extension, and this may be also used in the future if we can actually come up with an incremental build context api. If plugins are only injected with the project, any change to it may cause a rebuild or cache miss.

Both will continue to work, but if that is your concern can you file an issue regarding this, so it is not forgotten?

@michael-o michael-o deleted the MPLUGIN-495 branch January 7, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants